import React, { useEffect, useState } from 'react';
import { Modal, Form, Space } from 'antd';
import FormCondition from '@/components/FormCondition';
import { connect, history } from 'umi';
import { Button, Row, Col } from 'antd';
const updateLevel = (props) => {
  const { visible = false, onClose, loading, dispatch, handleCallback, cleanSelect, promoterLevelList } = props;
  const { show = false, detail = {}, selectIdList = [] } = visible;
  const { } = detail;

  const [form] = Form.useForm();
  // 确认提交
  const handleUpAudit = () => {
    form.validateFields().then((values) => {
      dispatch({
        type: 'promoter/fakeChangeLevel', payload: {
          ...values,
          idList: selectIdList,
        }, callback: () => {
          cleanSelect();
          handleCallback()
          onClose()
        }
      })

    });
  };

  const formItems = [
    {
      label: `等级`,
      name: 'levelId',
      type: 'select',
      style: { textAlign: 'left' },
      select: promoterLevelList,
      fieldNames: { label: 'levelName', value: 'id' },
      onChange: (e, val) => {
        const { option } = val
        form.setFieldValue('levelName', option.levelName)
      }
    },

    {
      label: `等级`,
      name: 'levelName',
      hidden: true
    },
  ];

  const modalProps = {
    title: '修改推广员等级',
    width: 800,
    visible: show,
    maskClosable: true,
    destroyOnClose: true,
    zIndex: 1001,
    confirmLoading: loading,
  };

  return (
    <Modal {...modalProps} onCancel={onClose} onOk={handleUpAudit}>
      <Space direction={'vertical'} style={{ display: 'flex', textAlign: 'left', justifyContent: 'center', width: '100%' }}>
        <FormCondition form={form} initialValues={{}} formItems={formItems}></FormCondition>
      </Space>

    </Modal >
  );
};

export default connect(({ order, loading }) => ({
  loading: loading.effects['promoter/fakeChangeLevel'],
}))(updateLevel);
;
